{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Teil 5 - Willkommen in der Sandkiste\n",
    "\n",
    "In den letzten Tutorials wurden der `hook` und auch alle Helfer jedesmal von Hand erstellt. Dies kann jedoch lästig werden, wenn es nur darum geht etwas auszuprobieren oder das Interface kennenzulernen. Deshalb werden von nun an diese Variablen aus Bequemlichkeit jeweils mit einer einzigen Funktion erstellt.\n",
    "\n",
    "Übersetzer:\n",
    "- Jan Moritz Behnken - Github: [@JMBehnken](https://github.com/JMBehnken)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:25:41.815062Z",
     "start_time": "2020-04-02T20:25:39.082848Z"
    }
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import syft as sy\n",
    "sy.create_sandbox(globals())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Was stellt die Sandkiste bereit?\n",
    "\n",
    "Wie oben zu erkennen ist, werden mehrere virtuelle Helfer erstellt und dabei direkt viele Datensätze auf sie verteilt. Somit können sie gleich genutzt werden, um die vertraulichen Techniken wie z. B. Federated Learning zu üben. \n",
    "\n",
    "Sechs Helfer werden erstellt ..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:28:59.364033Z",
     "start_time": "2020-04-02T20:28:59.336476Z"
    }
   },
   "outputs": [],
   "source": [
    "workers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Auch wurden diverse globale Variablen zum sofortigen Einsatz erstellt!!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:29:58.272572Z",
     "start_time": "2020-04-02T20:29:58.269581Z"
    }
   },
   "outputs": [],
   "source": [
    "hook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:29:58.685053Z",
     "start_time": "2020-04-02T20:29:58.680684Z"
    }
   },
   "outputs": [],
   "source": [
    "bob"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Teil 2: Helfer Such-Funktionalitäten\n",
    "\n",
    "Ein wichtiger Aspekt beim Praktizieren von Data Sciene aus der Ferne ist die Fähigkeit nach Datensätzen auf einem ferngesteuerten Helfer zu suchen. Ein mögliches Szenario ist zum Beispiel ein Forschungslabor, welches Krankenhäuser mit \"Radiologen\"-Datensätzen sucht."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:33:58.923195Z",
     "start_time": "2020-04-02T20:33:58.910636Z"
    }
   },
   "outputs": [],
   "source": [
    "x = torch.tensor([1,2,3,4,5]).tag(\"#fun\", \"#boston\", \"#housing\").describe(\"The input datapoints to the boston housing dataset.\")\n",
    "y = torch.tensor([1,2,3,4,5]).tag(\"#fun\", \"#boston\", \"#housing\").describe(\"The input datapoints to the boston housing dataset.\")\n",
    "z = torch.tensor([1,2,3,4,5]).tag(\"#fun\", \"#mnist\",).describe(\"The images in the MNIST training dataset.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:33:59.592321Z",
     "start_time": "2020-04-02T20:33:59.581296Z"
    }
   },
   "outputs": [],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:34:00.957402Z",
     "start_time": "2020-04-02T20:34:00.941830Z"
    }
   },
   "outputs": [],
   "source": [
    "x = x.send(bob)\n",
    "y = y.send(bob)\n",
    "z = z.send(bob)\n",
    "\n",
    "# this searches for exact match within a tag or within the description\n",
    "results = bob.search([\"#boston\", \"#housing\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:34:03.055031Z",
     "start_time": "2020-04-02T20:34:03.032418Z"
    }
   },
   "outputs": [],
   "source": [
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:34:27.355990Z",
     "start_time": "2020-04-02T20:34:27.347602Z"
    }
   },
   "outputs": [],
   "source": [
    "print(results[0].description)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Teil 3: Virtuelles Netz\n",
    "\n",
    "Ein Netz ist eine einfache Ansammlung von Helfern, welche Funktionen bereitstellen um bequem einen Datensatz zusammenzustellen."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:36:30.385880Z",
     "start_time": "2020-04-02T20:36:30.379497Z"
    }
   },
   "outputs": [],
   "source": [
    "grid = sy.PrivateGridNetwork(*workers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:36:32.248760Z",
     "start_time": "2020-04-02T20:36:32.222448Z"
    }
   },
   "outputs": [],
   "source": [
    "results = grid.search(\"#boston\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:36:33.226221Z",
     "start_time": "2020-04-02T20:36:33.206998Z"
    }
   },
   "outputs": [],
   "source": [
    "boston_data = grid.search(\"#boston\",\"#data\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-02T20:36:33.982374Z",
     "start_time": "2020-04-02T20:36:33.963796Z"
    }
   },
   "outputs": [],
   "source": [
    "boston_target = grid.search(\"#boston\",\"#target\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
